import { _decorator, Node } from 'cc';
import { BaseComponent } from '../../Manager/UIManager/BaseComponent';
import { GAME_POP, GAME_SCENE, GAME_TOP, GlobalData, SOUND_TYPE } from '../../Data/GlobalData';
import { TopPromptText } from '../../Top/TopPromptText';
const { ccclass, property } = _decorator;

@ccclass('GameScene')
/**
 * 游戏场景
 */
export class GameScene extends BaseComponent {

    //是否播放广告复活
    public IsAd: boolean = false;

    //麻将层
    @property(Node)
    public MangjiangLoad: Node = null;

    protected Init(): void {


    }

    protected OnShow(): void {
        this.IsAd = true;
        GlobalData.CurrentLevel = app.gameData.GameData.currentlevel;
        GlobalData.CurrentLevel = 0;

        this.GameStart();
    }

    /**
     * 开始游戏
     */
    public GameStart() {

        GlobalData.GameOver = false;

    }

    /**
     * 游戏过关
     */
    public GamePass() {


        GlobalData.CurrentLevel++;

        //更新本地关卡缓存
        if (GlobalData.CurrentLevel > app.gameData.GameData.currentlevel) {
            app.gameData.GameData.currentlevel = GlobalData.CurrentLevel
            app.gameData.UpdateGameDateLocal();
        }

        this.GameStart();
    }

    /**
     * 游戏结束
     */
    public GameOver() {

        GlobalData.GameOver = true;

        // if (this.IsAd) {
        //     this.IsAd = false;
        //     app.popManager.ShowPop(GAME_POP.PopAd)
        //     app.popManager.CurrentPop.getComponent(PopAd).SaveCb = () => {
        //         GlobalData.GameOver = false;
        //         //复活了
        //         app.popManager.HidePop(GAME_POP.PopAd);
        //     }

        //     app.popManager.CurrentPop.getComponent(PopAd).CloseCb = () => {
        //         app.popManager.HidePop(GAME_POP.PopAd);
        //         this.GameOver();
        //     }
        //     return;
        // }

        app.popManager.ShowPop(GAME_POP.PopEnd);

    }

    /**
     * 点击设置按钮
     */
    public SetClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.popManager.ShowPop(GAME_POP.PopSet);
    }

}